<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <title>try catch throw</title>
</head>

<body>
    <script>
    function myFunction() {
        try {
            var x = document.getElementById("demo").value;
            if (x == "") throw "empty";
            if (isNaN(x)) throw "not a number";
            if (x > 10) throw "too high";
            if (x < 5) throw "too low";
        } catch (err) {
            var y = document.getElementById("mess");
            y.innerHTML = "Error: " + err + ".";
        }
    }
    </script>

    <h1>My First JavaScript</h1>
    <p>Please input a number between 5 and 10:</p>
    <input id="demo" type="text">
    <button type="button" onclick="myFunction()">Test Input</button>
    <p id="mess" style="color:red;font-weight:bold;"></p>
</body>

</html>
